// pages/test/test.js
const network = require('../../../../utils/network.js')
var app = getApp();
var pageSize = 0;
var startTime_n;
var endTime_n;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headers: [{ text: 'rowNum', display: '排名' }, { text: 'diagName', display: '    疾病名称      ' }, { text: 'zeroToNine', display: '0-9' }, { text: 'tenToNineteen', display: '10-19' }, { text: 'twentyToTwentyNine', display: '20-29' }, { text: 'thirtyToThirtyNine', display: '30-39' }, { text: 'fortyToFortyNine', display: '40-49' }, { text: 'fiftyToFiftyNine', display: '50-59' }, { text: 'sixtyToSixtyNine', display: '60-69' }, { text: 'seventyToSeventyNine', display: '70-79' }, { text: 'eightyToEightyNine', display: '80-89' }, { text: 'ninetyToNinetyNine', display: '90-99' }, { text: 'hundred', display: '>100' }, { text: 'times', display: '合计' }],
    row: [],
    current: 1,
    totalPage: 1
  },
  onChange(e) {
    console.log('onChange', e)
    this.setData({
      current: e.detail.current,
    })
    this.myRequest(e)
  },

  myRequest: function (options) {
    var that = this;
    console.log('options:', options)
    //调用封装好的网络请求，获取数据
    var windowheight = wx.getSystemInfoSync().windowHeight;
    var tdHeight = [18.4, 21.6, 39]
    if (windowheight < 550) {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[0]);
    } else if (windowheight < 850) {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[1]);
    } else {
      pageSize = Math.round(windowheight * 0.8 / tdHeight[2]);
    }
      console.log("每页个数", pageSize);
    network.get('/ds/diseaseage?startTime=' + startTime_n + '&endTime=' + endTime_n + '&pageCount=' + that.data.current + '&pageSize=' + pageSize, {}).then(function (res) {
      console.log('res:', res)

      that.setData({
        startTime: startTime_n,
        endTime: endTime_n,
        msg: res.data.errMsg,
        row: res.data.data,
        totalPage: res.data.totalPage
      })
      console.log('row:', that.data.row)

    }).then(function (res) {
      wx.hideLoading()
      //that.createColumnChart();

    }).catch(function (res) {
      console.log(res)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    startTime_n = options.startTime
    endTime_n =options.endTime
    that.myRequest(options)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }, 
  onResize: function (res) {
    res.size.windowWidth, // 新的显示区域宽度
    res.size.windowHeight// 新的显示区域高度
    //console.log("监听屏幕旋转")
  }

})